%%

%byaccj

%{
  private Parser yyparser;

  public Yylex(java.io.Reader r, Parser yyparser) {
    this(r);
    this.yyparser = yyparser;
  }
%}

INT = [0-9]+
FLOAT = ([0-9]* "." [0-9]+) | ([0-9]+ "." [0-9]*)
CSTRING = "\"" .* "\""
FUNCSYM = "Func:"
PROGSYM = "Prog:"
IDENT = [a-zA-Z][a-zA-Z0-9]*
ISEQ = "=="
ISNE = "!="
LT = "<"
LE = "<="
GT = ">"
GE = ">="
PLUS = "+"
ASSIGN = "="
MINUS = "-"
MULT = "*"
DIV = "/"
CONV = "**"
SHL = "<<"
SHR = ">>"
IF = "if"
ELSE = "else"
WHILE = "while"
FOR = "for"
BREAK = "break"
CONTINUE = "continue"
RETURN = "return"
%%

/* types */

/* braces and parentheses and stuff */
";" |
"," |
"{" |
"}" |
"(" | 
"." |
":" |
"@" |
")"    { return (int) yycharat(0); }

"int" { yyparser.yylval = new ParserVal("int"); return Parser.TYPE_INT; }
"float" { yyparser.yylval = new ParserVal("float"); return Parser.TYPE_FLOAT; }
"Matrix" { yyparser.yylval = new ParserVal("Matrix"); return Parser.TYPE_MATRIX; }
"Image" { yyparser.yylval = new ParserVal("Image"); return Parser.TYPE_IMAGE; }
"void" { yyparser.yylval = new ParserVal("void"); return Parser.TYPE_VOID; }
"Histogram" { yyparser.yylval = new ParserVal("Histogram"); return Parser.TYPE_HISTOGRAM; }
"String" { yyparser.yylval = new ParserVal("String"); return Parser.TYPE_STRING; }
"Handle" { yyparser.yylval = new ParserVal("Handle"); return Parser.TYPE_HANDLE; }
{WHILE} { return Parser.WHILE; }
{FOR} { return Parser.FOR; }
{IF} { return Parser.IF; }
{ELSE} { return Parser.ELSE; }
{BREAK} { return Parser.BREAK; }
{CONTINUE} { return Parser.CONTINUE; }
{RETURN} { return Parser.RETURN; }
{IDENT}	{ yyparser.yylval = new ParserVal(yytext()); return Parser.IDENT; }
{CSTRING}	{ return Parser.CSTRING; }

/* float */
{FLOAT}  { yyparser.yylval = new ParserVal(Double.parseDouble(yytext()));
         return Parser.FLOAT; }
{INT}  { yyparser.yylval = new ParserVal(Integer.parseInt(yytext()));
         return Parser.INT; }
{FUNCSYM}	{ return Parser.FUNCSYM; }
{PROGSYM}	{ return Parser.PROGSYM; }
{ISEQ}	{ return Parser.ISEQ; }
{ISNE}	{ return Parser.ISNE; }
{LT}	{ return Parser.LT; }
{LE}	{ return Parser.LE; }
{GT}	{ return Parser.GT; }
{GE}	{ return Parser.GE; }
{PLUS}	{ return Parser.PLUS; }
{MINUS}	{ return Parser.MINUS; }
{MULT}	{ return Parser.MULT; }
{DIV}	{ return Parser.DIV; }
{CONV}	{ return Parser.CONV; }
{SHL}	{ return Parser.SHL; }
{SHR}	{ return Parser.SHR; }
{ASSIGN} { return Parser.ASSIGN; }

/* whitespace */
[ \t\n\r]+ { }

\b     { System.err.println("Sorry, backspace doesn't work"); }

/* error fallback */
[^]    { System.err.println("Error: unexpected character '"+yytext()+"'"); return -1; }
